package com.hw.one.dam2.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

import com.hw.one.dam2.entity.LampBlackEntity;
import com.hw.one.dam2.service.ILampBlackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hw.one.core.controller.BaseController;
import com.hw.one.core.result.MsgResult;
import com.hw.one.dam2.entity.PollutionIndustryEntity;
import com.hw.one.dam2.entity.RaiseDustEntity;
import com.hw.one.dam2.entity.WaterSurfaceEntity;
import com.hw.one.dam2.service.IIndustryPollutionService;
import com.hw.one.dam2.service.IWaterPollutionService;
import com.hw.one.dam2.service.IWaterSurfaceService;

/**
 * <p>
 * 工业污染源控制层类<br>
 * </p>
 */
@RestController
@RequestMapping(value = "industryPollution")
public class IndustryPollutionController extends BaseController {

	@Autowired
	private IIndustryPollutionService industryPollutionService;
	
	@Autowired
	private IWaterPollutionService waterPollutionService;
	
	@Autowired
	private IWaterSurfaceService waterSurfaceService;

	@Autowired
	private ILampBlackService lampBlackService;
	/**
	 * 获取污染源数据
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findIndustryPollutionData", method = RequestMethod.GET)
	public MsgResult findIndustryPollutionData(Model model, HttpServletRequest request) {
		try {
			
			return industryPollutionService.findIndustryPollutionBySiteCodeAndTime(request);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询工业污染源数据出现异常，后台程序异常。");
		}
		
	}
	
	/**
	 * 污染源历史曲线
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findPollutionTrendData", method = RequestMethod.GET)
	public MsgResult findPollutionTrendData(Model model, HttpServletRequest request) {
		// 点位类型
		// 工业源 industrySite 扬尘 raiseDustSite 油烟 lampblackSite 喷漆房 sprayBoothSite 
		String pointType = request.getParameter("pointType");
		if(null==pointType || "".equals(pointType)){
			return MsgResult.infoResult("查询条件点位类型pointType为空，查询失败。");
		}
		// 点位编码
		String pointCode = request.getParameter("pointCode");
		if(null==pointCode || "".equals(pointCode)){
			return MsgResult.infoResult("查询条件点位编码pointCode为空，查询失败。");
		}
		// 数据类型
		String dataType = request.getParameter("dataType");
		dataType = null==dataType || "".equals(dataType) ? "hourData" : dataType;
		
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		try {
			Map<String,Object> paraMap = new HashMap<String,Object>();
			paraMap.put("pointType", pointType);
			paraMap.put("pointCode", pointCode);
			paraMap.put("dataType", dataType);
			paraMap.put("startTime", startTime);
			paraMap.put("endTime", endTime);

			Object pollutionTrendObj = industryPollutionService.findPollutionTrendDataBySiteCodeAndSiteType(paraMap);
			
			return MsgResult.okResult(pollutionTrendObj);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询污染源历史曲线出现异常，后台程序异常。");
		}
	}

	/**
	 * 查询污染源数据的扬尘数据
	 * @author 李亚坤
	 * @createtime 2017年4月5日15:47:43
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findRaiseDustData", method = RequestMethod.GET)
	public MsgResult findRaiseDustData(HttpServletRequest request) {
		try {
			// 数据类型
			String dataType = request.getParameter("dataType");
			dataType = null==dataType || "".equals(dataType) ? "hourData" : dataType;
			String startTime = request.getParameter("startTime");
			String endTime = request.getParameter("endTime");
			Map<String, Object> paramMap = new HashMap<>();
			paramMap.put("dataType", dataType);
			paramMap.put("startTime", startTime);
			paramMap.put("endTime", endTime);
			paramMap.put("regionCode", request.getParameter("regionCode"));
			paramMap.put("companyName", request.getParameter("companyName"));
			paramMap.put("siteCodes", request.getParameter("siteCodes"));
			List<RaiseDustEntity> resultList = industryPollutionService.findRaiseDustData(paramMap);
			return MsgResult.okResult(resultList);
		}catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询污染源历史曲线出现异常，后台程序异常。");
		}
	}
	
	/**
	 * 获取工业废水数据
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findWaterPollutionData", method = RequestMethod.GET)
	public MsgResult findWaterPollutionData(Model model, HttpServletRequest request){
		try {
			
			List<PollutionIndustryEntity> waterDataList = waterPollutionService.findWaterPollutionDataByPSCode(request);
			
			return MsgResult.okResult(waterDataList);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询工业废水数据出现异常，后台程序异常。");
		}
		
	}
	
	/**
	 * 获取水质断面的数据
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findWaterSurfaceData", method = RequestMethod.GET)
	public MsgResult findWaterSurfaceData(Model model, HttpServletRequest request){
		try {
			List<WaterSurfaceEntity> waterSurfaceList = waterSurfaceService.findWaterSurfaceDataByPSCode(request);
			
			return MsgResult.okResult(waterSurfaceList);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询水质断面数据出现异常，后台程序异常。");
		}
		
	}

	/**
	 * 查询油烟数据
	 * @author 李亚坤
	 * @createtime 2017年5月23日17:47:34
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findLampBlackData", method = RequestMethod.GET)
	public MsgResult findLampBlackData(HttpServletRequest request) {
		try {
			List<LampBlackEntity> lampBlackEntities = lampBlackService.findLampBlackDataByRegionCode(request);
			return MsgResult.okResult(lampBlackEntities);
		}catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询油烟数据异常,后台程序异常");
		}
	}
	
}
